package com.game.web.controller.game;

import com.game.common.annotation.Log;
import com.game.common.core.controller.BaseController;
import com.game.common.core.domain.AjaxResult;
import com.game.common.core.page.TableDataInfo;
import com.game.common.enums.BusinessType;
import com.game.common.utils.poi.ExcelUtil;
import com.game.system.domain.game.CodeKey;
import com.game.system.service.ICodeKeyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 卡密Controller
 *
 * @author Mr.Liu
 * @date 2025-03-18
 */
@RestController
@RequestMapping("/game/key")
public class CodeKeyController extends BaseController
{
    @Autowired
    private ICodeKeyService codeKeyService;

    /**
     * 查询卡密列表
     */
    @PreAuthorize("@ss.hasPermi('game:key:list')")
    @GetMapping("/list")
    public TableDataInfo list(CodeKey codeKey)
    {
        startPage();
        List<CodeKey> list = codeKeyService.selectCodeKeyList(codeKey);
        return getDataTable(list);
    }

    /**
     * 导出卡密列表
     */
    @PreAuthorize("@ss.hasPermi('game:key:export')")
    @Log(title = "卡密", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CodeKey codeKey)
    {
        List<CodeKey> list = codeKeyService.selectCodeKeyList(codeKey);
        ExcelUtil<CodeKey> util = new ExcelUtil<CodeKey>(CodeKey.class);
        util.exportExcel(response, list, "卡密数据");
    }

    /**
     * 获取卡密详细信息
     */
    @PreAuthorize("@ss.hasPermi('game:key:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(codeKeyService.selectCodeKeyById(id));
    }

    /**
     * 新增卡密
     */
    @PreAuthorize("@ss.hasPermi('game:key:add')")
    @Log(title = "卡密", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CodeKey codeKey)
    {
        return toAjax(codeKeyService.insertCodeKey(codeKey));
    }

    /**
     * 修改卡密
     */
    @PreAuthorize("@ss.hasPermi('game:key:edit')")
    @Log(title = "卡密", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CodeKey codeKey)
    {
        return toAjax(codeKeyService.updateCodeKey(codeKey));
    }

    /**
     * 删除卡密
     */
    @PreAuthorize("@ss.hasPermi('game:key:remove')")
    @Log(title = "卡密", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(codeKeyService.deleteCodeKeyByIds(ids));
    }
}
